﻿using System;
using System.Collections;
using System.ComponentModel;
using MoonFramework.Template;
using UnityEngine;

namespace MoonFramework.Scripts.Mono
{
    /// <summary>
    /// Mono的管理者
    /// 1.声明周期函数
    /// 2.事件
    /// 3.协程
    /// </summary>
    public class MonoManager : BaseManager<MonoManager>
    {
        private MonoController _controller;

        public MonoManager()
        {
            //保证了MonoController对象的唯一性
            GameObject obj = new("MonoController");
            _controller = obj.AddComponent<MonoController>();
        }

        /// <summary>
        ///     提供给外部 用于外部帧更新事件函数
        /// </summary>
        /// <param name="_fun"></param>
        public void SendUpdateEvent(Action _fun)
        {
            _controller.SendEvent(_fun);
        }

        /// <summary>
        ///     提供给外部 用于移除外部帧更新事件函数
        /// </summary>
        /// <param name="_fun"></param>
        public void RemoveUpdateEvent(Action _fun)
        {
            _controller.RemoveEvent(_fun);
        }

        /// <summary>
        ///     开启协程
        /// </summary>
        /// <param name="routine"></param>
        /// <returns></returns>
        public Coroutine StartCoroutine(IEnumerator routine)
        {
            return _controller.StartCoroutine(routine);
        }

        public Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value)
        {
            return _controller.StartCoroutine(methodName, value);
        }

        public Coroutine StartCoroutine(string methodName)
        {
            return _controller.StartCoroutine(methodName);
        }

        public void Clear()
        {
            //去除
            _controller.Clear();
        }
    }
}